﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SosData;
using SosBL;
using RomControls;

namespace SosForms
{
    public partial class FormBase : Form
    {

        #region " Constructores "

        /// <Contructor>
        /// Constructor
        /// </summary>
        public FormBase()
        {
            InitializeComponent();
        }

        /// <FormBase_Load>
        /// Load Form
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        private void FormBase_Load(object sender, EventArgs e)
        {
            LoadFormPosition();
        }

        /// <FormBase_FormClosing>
        /// Save data before close the form
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        private void FormBase_FormClosing(object sender, FormClosingEventArgs e)
        {
            SaveFormPosition();
        }

        #endregion

        #region " Form Methods "

        /// <Load form position>
        /// Load position user form
        /// </summary>
        private void LoadFormPosition()
        {
            if (!this.DesignMode)
            {
                FormStatus form = DataBL.GetFormStatus(this);
                {
                    try
                    {
                        if (form.Maximized)
                        {
                            this.WindowState = FormWindowState.Maximized;
                        }
                        else
                        {
                            this.Width = form.Width;
                            this.Height = form.Height;
                            this.Left = form.LeftPosition;
                            this.Top = form.TopPosition;
                        }
                    }
                    catch { }
                }
            }
        }

        /// <Save form position>
        /// Save form position
        /// </summary>
        private void SaveFormPosition()
        {
            if (!this.DesignMode)
            {
                 SosBL.DataBL.FormStatusEdit(this);
            }
        }

        #endregion

        #region " Controls Methods "

        public enum EstadoControles { Habilitar = 1, Deshabilitar = 0 };

        /// <summary>
        /// Establecer estado de los controles del formulario.
        /// </summary>
        /// <param name="_estadoControles">enum (Habilitar, Deshabilitar)</param>
        public virtual void EstadoControlesForm(EstadoControles _estadoControles)
        {
            if (!this.DesignMode)
            {
                bool Habilitar = Convert.ToBoolean(_estadoControles);


                foreach (Control ctr in this.Controls)
                {
                    switch (ctr.GetType().ToString())
                    {
                        case "RomControls.RomButton":
                            RomButton but = (RomButton)ctr;
                            but.Enabled = Habilitar;
                            break;

                        case "RomControls.RomLabel":
                            RomLabel lbl = (RomLabel)ctr;
                            lbl.Enabled = Habilitar;
                            break;


                        case "RomControls.RomTextBox":
                            RomTextBox txt = (RomTextBox)ctr;
                            txt.ReadOnly = !Habilitar;
                            break;

                        case "RomControls.RomCheckBox":
                            RomCheckBox ch = (RomCheckBox)ctr;
                            ch.Enabled = Habilitar;
                            break;

                        case "RomControls.RomComboBox":
                            RomComboBox cmb = (RomComboBox)ctr;
                            cmb.Enabled = Habilitar;
                            break;

                        case "RomControls.RomDateTimePicker":
                            RomDateTimePicker dtp = (RomDateTimePicker)ctr;
                            dtp.Enabled = Habilitar;
                            break;

                        case "RomControls.RomGridView":
                            RomGridView dvg = (RomGridView)ctr;
                            dvg.ReadOnly = !Habilitar;
                            break;

                        case "RomControls.RomGroupBox":
                            RomGroupBox gb = (RomGroupBox)ctr;
                            gb.Enabled = Habilitar;
                            break;

                        case "RomControls.RomLinklbl":
                            RomLinkLabel Linklbl = (RomLinkLabel)ctr;
                            Linklbl.Enabled = Habilitar;
                            break;

                        case "RomControls.RomListView":
                            RomListView lv = (RomListView)ctr;
                            lv.Enabled = Habilitar;
                            break;

                        case "RomControls.RomMonthCalendar":
                            RomMonthCalendar mc = (RomMonthCalendar)ctr;
                            mc.Enabled = Habilitar;
                            break;

                        case "RomControls.RomNumBox":
                            RomNumBox numbox = (RomNumBox)ctr;
                            numbox.ReadOnly = !Habilitar;
                            break;

                        case "RomControls.RomNumericUpDown":
                            RomNumericUpDown numUpDown = (RomNumericUpDown)ctr;
                            numUpDown.ReadOnly = !Habilitar;
                            break;

                        case "RomControls.RomRadioButton":
                            RomRadioButton rb = (RomRadioButton)ctr;
                            rb.Enabled = Habilitar;
                            break;

                        case "RomControls.RomRichTextBox":
                            RomRichTextBox Richtxt = (RomRichTextBox)ctr;
                            Richtxt.ReadOnly = !Habilitar;
                            break;

                        case "RomControls.RomTreeView":
                            RomTreeView tv = (RomTreeView)ctr;
                            tv.Enabled = Habilitar;
                            break;
                        default:
                            break;
                    }
                }
            }
        }

        #endregion

    }
}
